<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Base Sprite</title>
</head>
<body>
  <canvas id="mycanvas" width="600" height="600"></canvas>
  <script src="/js/sprite-core.js"></script>
  <script>
    const Sprite = spritejs.Sprite;
    const Layer = spritejs.Layer;
    const Group = spritejs.Group;
    const Label = spritejs.Label;
    const context = document.getElementById('mycanvas').getContext('2d');
    const layer = new Layer({context, renderMode: 'repaintDirty'});

    const button = new Label('Press');
    button.attr({
      anchor: 0.5,
      pos: [200, 300],
      size: [200, 100],
      font: '64px Arial',
      textAlign: 'center',
      lineHeight: 100,
      border: {
        width: 6,
        color: '#333',
      },
      borderRadius: 20,
      fillColor: '#000',
    });

    layer.append(button);

    const transition = button.transition(0.5);
    button.on('mouseenter', (evt) => {
      transition.attr({
        bgcolor: '#666',
        fillColor: '#fff',
      });
    });

    button.on('mouseleave', (evt) => {
      transition.reverse();
    });

    button.on('mousedown', (evt) => {
      button.attr({scale: 0.9});
    });

    button.on('mouseup', (evt) => {
      button.attr({scale: 1.0});
    });

    mycanvas.addEventListener('mousemove', (evt) => {
      const {offsetX, offsetY} = evt;
      layer.dispatchEvent('mousemove', {layerX: offsetX, layerY: offsetY, originEvent: evt});
    });
  </script>
</body>
</html>